﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace Server
{
    public partial class Setup : Form
    {
        public IPAddress IP;
        public int Port;

        public Setup()
        {
            InitializeComponent();
            this.textBoxIP.Text = GetIP();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.textBoxPort.Text))
            {
                //this.IP = IPAddress.Parse(this.textBoxIP.Text);
                this.Port = System.Convert.ToInt16(this.textBoxPort.Text);
                Close();
            }
            else
                MessageBox.Show("You must enter a valid IP address and port.");
        }

        String GetIP()//redundant
        {
            String strHostName = Dns.GetHostName();
            IPHostEntry iphostentry = Dns.GetHostByName(strHostName);
            String IPStr = "";
            foreach (IPAddress ipaddress in iphostentry.AddressList)
            {
                IPStr = ipaddress.ToString();
                return IPStr;
            }
            return IPStr;
        }
    }
}
